package com.database;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.text.InputType;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v4.app.NavUtils;

public class DatabaseActivity extends Activity implements OnClickListener {

	private EditText text;
	private Button save, view, clear;
	private MyDatabase db;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_database);
        text = (EditText) findViewById(R.id.editText1);
        save = (Button) findViewById(R.id.save);
        save.setOnClickListener(this);
        view = (Button) findViewById(R.id.view);
        view.setOnClickListener(this);
        clear = (Button) findViewById(R.id.clear);
        clear.setOnClickListener(this);
        db = new MyDatabase(this);
    }
    
    public void onClick(View view) {
    	Log.d("DatabaseActivity", "Test"+text.getText().toString());
    	switch(view.getId()){
    	case R.id.save:
    		if (text.getText().length() == 0 || text.getText() == null) {
    			Toast.makeText(this, "Please enter a valid number", Toast.LENGTH_LONG).show();
    			return;
    		}
    		else{
    			db.addData(new Data(Long.parseLong(text.getText().toString())));
    			
    			showText("Data has been added: '"+text.getText().toString()+"'");
    		}
    		//Log.d("DatabaseActivity", "Test"+text.getText().toString());
    		break;
    	case R.id.view:
    		showContacts();
    		break;
    	case R.id.clear:
    		db.deleteAllData();
    		break;
    	}
	}
    
    public void showText(String str){
    	Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    }
    
    public void showContacts(){
    	
    }

}